import Koa from 'koa';
import dotenv from 'dotenv';
import Router from '@koa/router';
import { bodyParser } from '@koa/bodyparser';
import addModules from '#controller/index.js';
import { routerResponse } from '#utils/routerResponse.js';
import initSession from '#utils/session.js';
import httpMiddleware from '#utils/request.js';
import { getTime } from './src/utils/index.js';
dotenv.config();
const env = process.env;
const app = new Koa();

app.use(bodyParser());
app.use(routerResponse());
app.use(httpMiddleware());
app.use(initSession(app, {key: env.SESSION_KEY}));
const router = new Router();

await addModules(router, 'controller');

app.use(async (ctx, next) => {
  ctx.body = `Hello BurgerWang Koa！`;
  await next();
});

app.use(router.routes());
app.use(router.allowedMethods());
app.listen(env.PORT);

console.log(getTime() + ` start Koa! ${env.NODE_ENV} port:${env.PORT}| ${env.LARK_REDIRECT_URI}`);
